﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;


public partial class ybqy_1_11 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) { return; }

        SqlConnection sqlcon = new SqlConnection();
        sqlcon.ConnectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
        sqlcon.Open();

        SqlCommand sqlcmd = new SqlCommand("select * from a01111_2 where SERIAL='5100' and ShenBaoNianDu='" + Session["ShenBaoNianDu"] + "' and qiyeid=" + Session["qiyeid"] + " order by id", sqlcon);

        SqlDataReader reader = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);

        int i = 1;
        while (reader.Read())
        {
            if (i == 1)
            {
                POLLUTE_CODE1.SelectedValue = reader["POLLUTE_CODE"].ToString();
                PERMIT_VALUE1.Text = reader["PERMIT_VALUE"].ToString();
                MAX_DENSITY1.Text = reader["MAX_DENSITY"].ToString();
            }
            if (i == 2)
            {
                POLLUTE_CODE2.SelectedValue = reader["POLLUTE_CODE"].ToString();
                PERMIT_VALUE2.Text = reader["PERMIT_VALUE"].ToString();
                MAX_DENSITY2.Text = reader["MAX_DENSITY"].ToString();
            }
            if (i == 3)
            {
                POLLUTE_CODE3.SelectedValue = reader["POLLUTE_CODE"].ToString();
                PERMIT_VALUE3.Text = reader["PERMIT_VALUE"].ToString();
                MAX_DENSITY3.Text = reader["MAX_DENSITY"].ToString();
            }
            if (i == 4)
            {
                POLLUTE_CODE4.SelectedValue = reader["POLLUTE_CODE"].ToString();
                PERMIT_VALUE4.Text = reader["PERMIT_VALUE"].ToString();
                MAX_DENSITY4.Text = reader["MAX_DENSITY"].ToString();
            }
            i = i + 1;
        }
        sqlcmd.CommandText = "select * from a01111_2 where SERIAL='5200' and ShenBaoNianDu='" + Session["ShenBaoNianDu"] + "' and qiyeid=" + Session["qiyeid"] + " order by id";

        reader.Close();
        sqlcon.Open();
        reader = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);

        i = 1;
        while (reader.Read())
        {
            if (i == 1)
            {
                POLLUTE_CODE5.SelectedValue = reader["POLLUTE_CODE"].ToString();
                PERMIT_VALUE5.Text = reader["PERMIT_VALUE"].ToString();
                MAX_DENSITY5.Text = reader["MAX_DENSITY"].ToString();
            }
            if (i == 2)
            {
                POLLUTE_CODE6.SelectedValue = reader["POLLUTE_CODE"].ToString();
                PERMIT_VALUE6.Text = reader["PERMIT_VALUE"].ToString();
                MAX_DENSITY6.Text = reader["MAX_DENSITY"].ToString();
            }
            if (i == 3)
            {
                POLLUTE_CODE7.SelectedValue = reader["POLLUTE_CODE"].ToString();
                PERMIT_VALUE7.Text = reader["PERMIT_VALUE"].ToString();
                MAX_DENSITY7.Text = reader["MAX_DENSITY"].ToString();
            }
            if (i == 4)
            {
                POLLUTE_CODE8.SelectedValue = reader["POLLUTE_CODE"].ToString();
                PERMIT_VALUE8.Text = reader["PERMIT_VALUE"].ToString();
                MAX_DENSITY8.Text = reader["MAX_DENSITY"].ToString();
            }
            i = i + 1;
        }
        sqlcmd.CommandText = "select * from a01111_1 where SERIAL='5100' and ShenBaoNianDu='" + Session["ShenBaoNianDu"] + "' and qiyeid=" + Session["qiyeid"];

        reader.Close();
        sqlcon.Open();
        reader = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);

        if (reader.Read())
        {
            PERMIT_COUNTs.Text = reader["PERMIT_COUNT"].ToString();
        }
        sqlcmd.CommandText = "select * from a01111_1 where SERIAL='5200' and ShenBaoNianDu='" + Session["ShenBaoNianDu"] + "' and qiyeid=" + Session["qiyeid"];

        reader.Close();
        sqlcon.Open();
        reader = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);

        if (reader.Read())
        {
            PERMIT_COUNTq.Text = reader["PERMIT_COUNT"].ToString();
        }


    }

    protected void dlc()
    {
        if (POLLUTE_CODE1.SelectedValue == POLLUTE_CODE2.SelectedValue && POLLUTE_CODE1.Text != "" && POLLUTE_CODE2.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE1.SelectedValue == POLLUTE_CODE3.SelectedValue && POLLUTE_CODE1.Text != "" && POLLUTE_CODE3.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE1.SelectedValue == POLLUTE_CODE4.SelectedValue && POLLUTE_CODE1.Text != "" && POLLUTE_CODE4.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE2.SelectedValue == POLLUTE_CODE3.SelectedValue && POLLUTE_CODE2.Text != "" && POLLUTE_CODE3.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE2.SelectedValue == POLLUTE_CODE4.SelectedValue && POLLUTE_CODE2.Text != "" && POLLUTE_CODE4.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE3.SelectedValue == POLLUTE_CODE4.SelectedValue && POLLUTE_CODE3.Text != "" && POLLUTE_CODE4.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }


        if (POLLUTE_CODE5.SelectedValue == POLLUTE_CODE6.SelectedValue && POLLUTE_CODE5.Text != "" && POLLUTE_CODE6.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE5.SelectedValue == POLLUTE_CODE7.SelectedValue && POLLUTE_CODE5.Text != "" && POLLUTE_CODE7.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE5.SelectedValue == POLLUTE_CODE8.SelectedValue && POLLUTE_CODE5.Text != "" && POLLUTE_CODE8.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE6.SelectedValue == POLLUTE_CODE7.SelectedValue && POLLUTE_CODE6.Text != "" && POLLUTE_CODE7.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE6.SelectedValue == POLLUTE_CODE8.SelectedValue && POLLUTE_CODE6.Text != "" && POLLUTE_CODE8.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }
        if (POLLUTE_CODE7.SelectedValue == POLLUTE_CODE8.SelectedValue && POLLUTE_CODE7.Text != "" && POLLUTE_CODE8.Text != "")
        {
            Response.Write("<script>alert('重复！！！')</script>");
        }


        if (POLLUTE_CODE1.SelectedValue == "001" || POLLUTE_CODE1.SelectedValue == "002")
        {
            PERMIT_VALUE1.Enabled = false;
        }
        else
        {
            PERMIT_VALUE1.Enabled = true;
        }
        if (POLLUTE_CODE2.SelectedValue == "001" || POLLUTE_CODE2.SelectedValue == "002")
        {
            PERMIT_VALUE2.Enabled = false;
        }
        else
        {
            PERMIT_VALUE2.Enabled = true;
        }
        if (POLLUTE_CODE3.SelectedValue == "001" || POLLUTE_CODE3.SelectedValue == "002")
        {
            PERMIT_VALUE3.Enabled = false;
        }
        else
        {
            PERMIT_VALUE3.Enabled = true;
        }
        if (POLLUTE_CODE4.SelectedValue == "001" || POLLUTE_CODE4.SelectedValue == "002")
        {
            PERMIT_VALUE4.Enabled = false;
        }
        else
        {
            PERMIT_VALUE4.Enabled = true;
        }
        if (POLLUTE_CODE5.SelectedValue == " 00")
        {
            PERMIT_VALUE5.Enabled = false;
        }
        else
        {
            PERMIT_VALUE5.Enabled = true;
        }
        if (POLLUTE_CODE6.SelectedValue == " 00")
        {
            PERMIT_VALUE6.Enabled = false;
        }
        else
        {
            PERMIT_VALUE6.Enabled = true;
        }
        if (POLLUTE_CODE7.SelectedValue == " 00")
        {
            PERMIT_VALUE7.Enabled = false;
        }
        else
        {
            PERMIT_VALUE7.Enabled = true;
        }
        if (POLLUTE_CODE8.SelectedValue == " 00")
        {
            PERMIT_VALUE8.Enabled = false;
        }
        else
        {
            PERMIT_VALUE8.Enabled = true;
        }




    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection sqlcon = new SqlConnection();
        sqlcon.ConnectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
        sqlcon.Open();

        SqlCommand sqlcmd = new SqlCommand("delete a01111_2 where  ShenBaoNianDu='" + Session["ShenBaoNianDu"] + "' and qiyeid=" + Session["qiyeid"], sqlcon);
        Label5.Text = "";
        sqlcmd.ExecuteNonQuery();
        string sqlstr = "";

        if (POLLUTE_CODE1.Text != "")
        {
            sqlstr = @"insert into a01111_2(qiyeid,ShenBaoNianDu,FACT_ID,PERMIT_YEAR,POLLUTE_CODE,SERIAL,PERMIT_VALUE,MAX_DENSITY,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "','" +
                POLLUTE_CODE1.Text.Trim() + "',5100,'" +
                PERMIT_VALUE1.Text.Trim() + "','" +
                MAX_DENSITY1.Text.Trim() + "','weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }

        if (POLLUTE_CODE2.Text != "")
        {
            sqlstr = @"insert into a01111_2(qiyeid,ShenBaoNianDu,FACT_ID,PERMIT_YEAR,POLLUTE_CODE,SERIAL,PERMIT_VALUE,MAX_DENSITY,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "','" +
                POLLUTE_CODE2.Text.Trim() + "',5100,'" +
                PERMIT_VALUE2.Text.Trim() + "','" +
                MAX_DENSITY2.Text.Trim() + "','weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }

        if (POLLUTE_CODE3.Text != "")
        {
            sqlstr = @"insert into a01111_2(qiyeid,ShenBaoNianDu,FACT_ID,PERMIT_YEAR,POLLUTE_CODE,SERIAL,PERMIT_VALUE,MAX_DENSITY,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "','" +
                POLLUTE_CODE3.Text.Trim() + "',5100,'" +
                PERMIT_VALUE3.Text.Trim() + "','" +
                MAX_DENSITY3.Text.Trim() + "','weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }

        if (POLLUTE_CODE4.Text != "")
        {
            sqlstr = @"insert into a01111_2(qiyeid,ShenBaoNianDu,FACT_ID,PERMIT_YEAR,POLLUTE_CODE,SERIAL,PERMIT_VALUE,MAX_DENSITY,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "','" +
                POLLUTE_CODE4.Text.Trim() + "',5100,'" +
                PERMIT_VALUE4.Text.Trim() + "','" +
                MAX_DENSITY4.Text.Trim() + "','weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }

        if (POLLUTE_CODE5.Text != "")
        {
            sqlstr = @"insert into a01111_2(qiyeid,ShenBaoNianDu,FACT_ID,PERMIT_YEAR,POLLUTE_CODE,SERIAL,PERMIT_VALUE,MAX_DENSITY,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "',' " +
                POLLUTE_CODE5.Text.Trim() + "',5200,'" +
                PERMIT_VALUE5.Text.Trim() + "','" +
                MAX_DENSITY5.Text.Trim() + "','weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }

        if (POLLUTE_CODE6.Text != "")
        {
            sqlstr = @"insert into a01111_2(qiyeid,ShenBaoNianDu,FACT_ID,PERMIT_YEAR,POLLUTE_CODE,SERIAL,PERMIT_VALUE,MAX_DENSITY,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "',' " +
                POLLUTE_CODE6.Text.Trim() + "',5200,'" +
                PERMIT_VALUE6.Text.Trim() + "','" +
                MAX_DENSITY6.Text.Trim() + "','weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }

        if (POLLUTE_CODE7.Text != "")
        {
            sqlstr = @"insert into a01111_2(qiyeid,ShenBaoNianDu,FACT_ID,PERMIT_YEAR,POLLUTE_CODE,SERIAL,PERMIT_VALUE,MAX_DENSITY,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "',' " +
                POLLUTE_CODE7.Text.Trim() + "',5200,'" +
                PERMIT_VALUE7.Text.Trim() + "','" +
                MAX_DENSITY7.Text.Trim() + "','weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }

        if (POLLUTE_CODE8.Text != "")
        {
            sqlstr = @"insert into a01111_2(qiyeid,ShenBaoNianDu,FACT_ID,PERMIT_YEAR,POLLUTE_CODE,SERIAL,PERMIT_VALUE,MAX_DENSITY,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "',' " +
                POLLUTE_CODE8.Text.Trim() + "',5200,'" +
                PERMIT_VALUE8.Text.Trim() + "','" +
                MAX_DENSITY8.Text.Trim() + "','weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }


        sqlstr = "delete a01111_1 where  ShenBaoNianDu='" + Session["ShenBaoNianDu"] + "' and qiyeid=" + Session["qiyeid"];
        sqlcmd.CommandText = sqlstr;
        sqlcmd.ExecuteNonQuery();

        if (PERMIT_COUNTs.Text != "")
        {
            sqlstr = @"insert into a01111_1(qiyeid,ShenBaoNianDu,FACT_ID,DATA_MONTH,PERMIT_COUNT,SERIAL,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "','" +
                PERMIT_COUNTs.Text.Trim() + "',5100,'weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }
        if (PERMIT_COUNTq.Text != "")
        {
            sqlstr = @"insert into a01111_1(qiyeid,ShenBaoNianDu,FACT_ID,DATA_MONTH,PERMIT_COUNT,SERIAL,jy)values(" +
                Session["qiyeid"] + ",'" +
                Session["ShenBaoNianDu"] + "','1','" +
                Session["ShenBaoNianDu"] + "','" +
                PERMIT_COUNTq.Text.Trim() + "',5200,'weijiaoyan')";

            sqlcmd.CommandText = sqlstr;
            sqlcmd.ExecuteNonQuery();
        }

        sqlstr = "update  a01101 set jy='ruanjian' where ShenBaoNianDu='" + Session["ShenBaoNianDu"] + "' and qiyeid=" + Session["qiyeid"];
        sqlcmd.CommandText = sqlstr;
        sqlcmd.ExecuteNonQuery();
        sqlcon.Close();
        Label5.Text = "更新完成";





    }
    protected void POLLUTE_CODE1_SelectedIndexChanged(object sender, EventArgs e)
    {
        dlc();
    }
    protected void POLLUTE_CODE1_TextChanged(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_TextChanged(object sender, EventArgs e)
    {

    }
    protected void POLLUTE_CODE3_Init(object sender, EventArgs e)
    {

    }
    protected void POLLUTE_CODE1_Init(object sender, EventArgs e)
    {

    }
    protected void POLLUTE_CODE1_PreRender(object sender, EventArgs e)
    {
        dlc();
    }
    public string DisplayStr()
    {
        YingYongHanShu yyhs = new YingYongHanShu();

        return yyhs.DisplayStr2("101111");
    }

}